import {Component, OnInit, ViewEncapsulation} from '@angular/core';
import {AuthService} from "@shared/service/auth/auth.service";
import {ActivatedRoute, Params} from "@angular/router";
import {ParentService} from "@train/parent/parent.service";
import {TestScoreStandardVO} from "@interface/index";

@Component({
  selector: 'seed-score-standard',
  templateUrl: './score-standard.component.html',
  styleUrls: ['./score-standard.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class ScoreStandardComponent implements OnInit {
  public authOrgId: string;
  public ageId: number;
  public itemId: number;
  public titleName = {
    itemName: '',
    itemModuleName: '',
    age: ''
  };
  public standardList: Array<TestScoreStandardVO> = [];
  public testDesc: string;

  constructor(
    private authService: AuthService,
    private activatedRoute: ActivatedRoute,
    private parentService: ParentService
  ) {
    this.authOrgId = authService.getAuthOrgId();
    activatedRoute.queryParams.switchMap((param: Params) => {
      this.titleName['itemName'] = param['itemName'];
      this.titleName['itemModuleName'] = param['itemModuleName'];
      this.titleName.age = param['age'];
      return this.activatedRoute.params;
    }).subscribe((param: Params) => {
      this.ageId = param['ageId'];
      this.itemId = param['itemId'];
      this.standard();
    })
  }

  /**
   * @author guoqs1331
   * @time 2018/4/16
   * @description
   */
  standard() {
    const param = {
      orgUserId: this.authOrgId,
      ageId: this.ageId,
      itemId: this.itemId
    };
    this.parentService.standard(param).subscribe(res => {
      let {standardList, testDesc} = res['data'];
      this.standardList = standardList;
      this.testDesc = testDesc;
    })
  }

  ngOnInit() {
  }

}
